package gpl.scotlandyard.detective.hint.main;

import gpl.androidcommons.scotlandyard.DummyFactory;
import gpl.scotlandyard.detective.hint.ApplicationManager;
import gpl.scotlandyard.detective.hint.R;

import java.util.Locale;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class MainSectionPagerAdapter extends FragmentPagerAdapter {

  private static final int MAP_WEIGHT_POSITION = 0;
  private MainActivity mainActivity;

  public MainSectionPagerAdapter(FragmentManager fm, MainActivity mainActivity) {
    super(fm);
    this.mainActivity = mainActivity;
  }

  @Override
  public Fragment getItem(int position) {
    if (position == MAP_WEIGHT_POSITION) {
      ApplicationManager.push(MainFragment.ARG_MAP, mainActivity.getBoardMap());
      ApplicationManager.push(MainFragment.ARG_PLAYERS, DummyFactory.players(5));
      return new MainFragment();
    }
    return null;
  }

  @Override
  public int getCount() {
    return 1;
  }

  @Override
  public CharSequence getPageTitle(int position) {
    Locale l = Locale.getDefault();
    switch (position) {
      case MAP_WEIGHT_POSITION:
        return mainActivity.getString(R.string.section_title_map_weight).toUpperCase(l);
    }
    return "no title";
  }
}
